package homework_4.write_2;

public class Score {
    public double s[];

    public Score(double[] s) {
        this.s = s;
    }

    public double max(){
        double i = s[0];
        for(int j = 1; j < s.length; j++){
            if(i < s[j]){
                i = s[j];
            }
            else;
        }
        return i;
    }

    public double min(){
        double i = s[0];
        for(int j = 1; j < s.length; j++){
            if(i > s[j]){
                i = s[j];
            }
            else;
        }
        return i;
    }

    public double average(){
        double sum = 0;
        for(int i = 0; i < s.length; i++){
            sum += s[i];
        }
        return sum;
    }

    public void check() throws WrongData {
        for(int i = 0; i < s.length; i++){
            if(s[i] < 0 || s[i] > 100){
                throw new WrongData("分数错误");
            }
        }
    }

    public static void main(String[] args) {
        double[] s1 = new double[]{85,86,87.5,92.5,94,95};
        double[] s2 = new double[]{-20,102,88};

        Score s_1 = new Score(s1);
        Score s_2 = new Score(s2);

        try{
            s_1.check();
            System.out.println("min= "+ s_1.min());
            System.out.println("max= "+ s_1.max());
            System.out.println("average= "+ s_1.average());
        }
        catch (WrongData e){
            System.out.println(e.getMessage());
        }

        try{
            s_2.check();
            System.out.println("min= "+ s_2.min());
            System.out.println("max= "+ s_2.max());
            System.out.println("average= "+ s_2.average());
        }
        catch (WrongData e){
            System.out.println(e.getMessage());
        }

    }

}
